<!DOCTYPE html>
<html lang="zh">

<head>
	<th:block th:include="include :: header('开票申请')" />
	<link href="../static/layui/css/layui.css" th:href="@{/layui/css/layui.css}" rel="stylesheet" />
	<link href="../static/layui/css/dropdown.css" th:href="@{/layui/css/dropdown.css}" rel="stylesheet" />
	<link href="../static/css/projectDetail.css" th:href="@{/css/projectDetail.css}" rel="stylesheet" />
</head>

<body class="fixed-sidebar full-height-layout gray-bg">
	<!-- 头部导航 链接 -->
	<div class="row border-bottom white-bg dashboard-header headerNav">
		<div class="col-sm-1 logo">
			<div class="icon hidden-xs">
				<i class="fa fa-file-powerpoint-o"></i>
			</div>
			<div class="progressBar">
				<i>20.00%</i>
				<!-- style和 aria-valuenow里的数字代表进度 -->
				<div class="layui-progress" style="height: 5px;">
					<div class="layui-progress-bar " lay-percent="20.00%" style="width: 20%;"></div>
				</div>
			</div>
		</div>
		<div class="col-sm-11 navBar">
			<th:block th:include="include :: projectYyBar" />
		</div>
	</div>
		
	<!-- 主体部分 -->
	<div class="wrapper wrapper-content">
		<div class="btn-group-sm" id="toolbar" role="group">
<!-- 				<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="gcgl:sqkp:add"> -->
<!-- 	                <i class="fa fa-plus"></i> 添加 -->
<!-- 	            </a> -->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gcgl:yysqkp:export">
                    <i class="fa fa-download"></i> 导出
                </a>
<!--                 <a class="btn btn-success single disabled" onclick="sqkpfpadd()" shiro:hasPermission="gcgl:sqkpfp:add"> -->
<!--                     <i class="fa fa-edit"></i> 上传销项发票 -->
<!--                 </a> -->
<!--                 <a class="btn btn-info single disabled" id="button-yes" shiro:hasPermission="gcgl:qrsk:add"> -->
<!--                     <i class="fa fa-check"></i> 确认收款 -->
<!--                 </a> -->
<!--                 <a class="btn btn-info single disabled" id="button-lis" shiro:hasPermission="gcgl:qrsk:view"> -->
<!--                     <i class="fa fa-check"></i> 查看收款台账 -->
<!--                 </a> -->
        </div>
		<div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
	</div>
	<!-- import layui -->
	<th:block th:include="include :: footer" />
	<script th:src="@{/layui/dropdown.js?v=20250801}"></script>
	<th:block th:include="include :: projectYyDetail" />
	<!-- import layui -->
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('gcgl:yysqkp:edit')}]];
	    var removeFlag = [[${@permission.hasPermi('gcgl:yysqkp:remove')}]];
	    var types = [[${@dict.getType('sj_nsct_type')}]];
	    var fps = [[${@dict.getType('gcgl_project_fp')}]];
		var statuss = [[${@dict.getType('sj_contract_status')}]];
	    var prefix = ctx + "yy/sqkp";
        
        $(function() {
            var options = {
                url: prefix + "/p4list",
                createUrl: prefix + "/add/"+$("#id").val(),
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "开票申请",
//                 pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sortName: "id desc",
                sortOrder: "",
                queryParams: queryParams,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'gcProjectid',
                    title: '合同ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '合同编号'
                },
                {
                    field: 'xmmc',
                    title: '项目名称'
                },
                {
                    field: 'sqsj',
                    title: '申请时间'
                },
                {
                    field: 'xmfzr',
                    title: '项目负责人'
                },
                {
                    field: 'htje',
                    title: '合同金额'
                },
                {
		            field: 'xmlx',
		            title: '项目类型',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(types, item.xmlx);
		            }
		        },
                {
                    field: 'bcsqkpje',
                    title: '本次申请开票金额',
                    visible: false
                },
                {
                    field: 'yjskje',
                    title: '预计收款金额',
                    visible: false
                },
                {
		            field: 'fplx',
		            title: '发票类型',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(fps, item.fplx);
		            }
		        },
                {
                    field: 'shuih',
                    title: '单位信息名称/税号',
                    visible: false
                },
                {
                    field: 'kaihuh',
                    title: '单位信息开户行/帐号',
                    visible: false
                },
                {
                    field: 'dizhi',
                    title: '单位信息地址/电话',
                    visible: false
                },
                {
                    field: 'ykfpsj',
                    title: '已开发票时间',
                    visible: false
                },
                {
                    field: 'itemje',
                    title: '申请开票金额'
                },
                {
                    field: 'ykfpje',
                    title: '已开发票金额',
                    visible: false
                },
                {
                    field: 'hej',
                    title: '合计(累计开票金额)',
                    visible: false
                },
                {
		            field: 'status',
		            title: '状态',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(statuss, item.status);
		            }
		        },
                {
                    field: 'spyj',
                    title: '审批意见',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    	
                        if(row.status==1){
                        	actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }else{
//                             actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="traceProcess(\'' + row.processInstanceId + '\')" ><i class="fa fa-area-chart"></i>流程图</a>&nbsp;');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="run(\'' + row.processInstanceId + '\')"><i class="fa fa-file-archive-o"></i>流程进度</a>&nbsp;');
                        }
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="sqkpprint(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function queryParams(params){
        	var search = $.table.queryParams(params);
        	search.gcProjectid = $("#id").val();
        	return search;
        }
        
      //确认收款
        $("#button-yes").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            var status = $.table.selectColumns("status");
            
            if(status==5){
            	$.modal.open('确认收款',"/yy/qrsk/add/"+rows.join());
            	/**
            	$.modal.confirm("确认该款项收款吗?", function() {
    	    		$.ajax({
        				url: "/gcgl/sqkp/hjconfirm",
        				type: "post",
        				data: { "ids": rows.join() },
        				dataType: 'json',
        				success: function(data) {
        					$.table.refresh();
        				},
        				error: function(xhr, type, errorThrown) {
        					//异常处理；
        					$.modal.alert("请稍后再试！");
        					$.table.refresh();
        				}
        			});
    	    	});
            	**/
            }else if(status==5){
            	$.modal.alertWarning("该记录已付款完成！");
                return;
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
	    })
	    
	  	//查看收款台账
        $("#button-lis").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            $.modal.open('确认付款',"/yy/qrsk/"+rows.join());
	    })
	    
	    //打印增值税发票开具申请单
	    function sqkpprint(id){
            $.modal.openTab('查看',"/yy/sqkp/sqkpprint/"+id);
        }
        
        function sqkpfpadd(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            $.modal.open('新增销项发票',"/yy/sqkpfp/add/"+rows.join());
        }
        
        function run(processInstanceId) {
            $.modal.open("执行记录", ctx + "flow/monitor/historyDetail?processInstanceId=" + processInstanceId);
        }
        
        function traceProcess(processInstanceId) {
            $.modal.openTab("流程进度", ctx + "flow/monitor/traceProcess/"+processInstanceId);
        }
    </script>
    <!--选中导航 这段js放在每个页面末尾-->
    <script>
		$(()=>{
			setTimeout(()=>{
				selectedNav(10)//第N个被选中 0即
			},100)
		})
		
		function selectedNav(index){
			$('ul.layui-nav').find('.layui-nav-item').eq(index).addClass('layui-this');
		}
	</script>
</body>
</html>